package com.taxigang.server;

import java.io.Serializable;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;

import com.google.appengine.api.datastore.Key;
import com.taxigang.shared.TaxiCompanyInfo;

/**
 *
 * @author hall
 */
@Entity
@Table(name = "TAXICOMPANY")
@NamedQueries({	@NamedQuery(	name = "TaxiCompany.findAll", 				query = "SELECT a FROM TaxiCompany a "),
				@NamedQuery(	name = "TaxiCompany.find", 					query = "SELECT a FROM TaxiCompany a WHERE a.postalCode = :postalCode")}) 
public class TaxiCompany implements Serializable {
	private static final long serialVersionUID = 1L;
	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	@Column(name = "TAXICOMPANYKEY", nullable = false)
	private Key key;
	@Column(name = NAME, nullable = true)
	private String name;
	@Column(name = POSTALCODE, nullable = true)
	private String postalCode;

	@Column(name = LAT, nullable = true)
	private Double lat;
	@Column(name = LNG, nullable = true)
	private Double lng;

	@Column(name = TELAREACODE, nullable = true)
	private String telAreaCode;

	@Column(name = TELNO, nullable = true)
	private String telNo;

	@Column(name = URL, nullable = true)
	private String url;

	public static final  String TELAREACODE="TELAREACODE";
	public static final  String TELNO="TELNO";
	public static final  String URL="URL";
	public static final  String STARTLAT="STARTLAT";
	public static final  String STARTLONG="STARTLONG";
	public static final  String ENDLAT="ENDLAT";
	public static final  String ENDLONG="ENDLONG";
	public static final  String NAME="NAME";
	public static final  String POSTALCODE="POSTALCODE";
    public static final  String LAT="LAT";
    public static final  String LNG="LNG";


	public TaxiCompany() {
	}

	public long getId() {
		return key.getId();
	}

	public TaxiCompanyInfo getInfo(){
		TaxiCompanyInfo info =  new TaxiCompanyInfo();
		info.setId(getId());
		info.setName(name);
		info.setTelNo(telNo);
		info.setTelAreaCode(telAreaCode);
		info.setPostalCode(postalCode);
		info.setLatLng(lat,lng);
		info.setUrl(url);
		return info;
	}


	public void setInfo(TaxiCompanyInfo info){
		name =info.getName();
		telNo = info.getTelNo();
		telAreaCode = info.getTelAreaCode();
		postalCode = info.getPostalCode();
		lat = info.getLat();
		lng = info.getLng();
		url = info.getUrl();
	}


	@Override
	public boolean equals(Object object) {
		// TODO: Warning - this method won't work in the case the id fields are not set
		if (!(object instanceof TaxiCompany)) {
			return false;
		}
		TaxiCompany other = (TaxiCompany) object;
		if ((this.key == null && other.key != null) || (this.key != null && !this.key.equals(other.key))) {
			return false;
		}
		return true;
	}

	@Override
	public String toString() {
		return "taxigangsystem.beans.TaxiCompany[taxiCompany=" + key.getId() + "]";
	}

}
